package cc.idoone.spring_boot_hello.actuator;

import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 自定义监控端点
 *
 * @author hemj
 * @since 2017/10/18
 */
@Component
@ConfigurationProperties(prefix = "endpoints.servertime")
public class ServerTimeEndpoint extends AbstractEndpoint<Map<String, Object>> {

	// http://localhost:8080/servertime
	// http://localhost:8080/manage/servertime
	public ServerTimeEndpoint() {
		// 两个参数分别表示端点 ID 和是否端点默认是敏感的
		super("servertime", false);
	}

	@Override
	public Map<String, Object> invoke() {
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("server_time", System.currentTimeMillis());
		return result;
	}
}
